package com.xuchao.rabbit.b2;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xuchao.rabbit.utils.RabbitMqUtils;

/**
 * @Author xuchao
 * @Date:2023/6/6 17:02
 * @description 多线程处理消息
 * @Version 1.0
 */
public class Worker01 {
    //队列名称
    public static final String QUEUE_NAME = "hello";

    //接收消息
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        DeliverCallback deliverCallback = (consumerTage,message)->{
            System.out.println(new String(message.getBody()));
        };
        CancelCallback cancelCallback = consumerTage -> {
            System.out.println("消息消费被中断:"+consumerTage);
        };
        /**
         * 消费者接收消息
         * 1.队列名
         * 2.是否自动应答
         * 3.消费者未成功消费的回调
         * 4.消费者消费被中断的回调
         */
        System.out.println("c3在接收消息");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
